package com.zhhs.galaxyott.httpVolley.parser;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.text.TextUtils;
import android.util.Log;

import com.zhhs.galaxyott.beans.HomeMovieBean;
import com.zhhs.galaxyott.httpVolley.response.HomemovieListResponse;

public class HomemovieListParser extends BaseParser<HomemovieListResponse> {

    @Override
    public HomemovieListResponse parse(String jsonString) {
        if (TextUtils.isEmpty(jsonString)) {
            return null;
        }
        HomemovieListResponse response = new HomemovieListResponse();

        try {
            // 如果用fastJoson就是此处不同
            // JSONObject obj = JSON.parseObject(paramString);
            JSONObject obj = new JSONObject(jsonString);
            parseMsg(obj, response);

            Log.i("DEBUG_LC", "THIS IS returnCode != 0");
            if (response.errCode == 0) {// 返回正常.

                JSONArray recordList = obj.getJSONArray("list");
                Log.i("DEBUG_LC", "THIS IS returnCode = 0" + recordList.length());
                for (int i = 0; i < recordList.length(); i++) {
                    HomeMovieBean homeMovieBean = new HomeMovieBean();
                    JSONObject jo = recordList.getJSONObject(i);
                    homeMovieBean.setAdTitle(jo.optString("adTitle"));
                    homeMovieBean.setPage(jo.optString("page"));
                    homeMovieBean.setPageModule(jo.optString("pageModule"));
                    homeMovieBean.setAdType(jo.optString("adType"));
                    homeMovieBean.setObjectid(jo.optString("objectId"));
                    homeMovieBean.setImageUrl(jo.optString("imageUrl"));
                    if (jo.has("adSort")) {
                        homeMovieBean.setAdSort(jo.optString("adSort"));
                    }
                    response.homeMovieBeans.add(homeMovieBean);
                }
                Log.i("DEBUG_LC", "THIS IS response" + response.homeMovieBeans.size());
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return response;
    }

}
